<?php
namespace Nawa\MedicalStudy\MedicalCenter;
/**
 * Patient of Medical Center Partner.
 *
 * It represant a Patient of the medical center
 *
 * @author Xavier VILAIN
 * @package Nawa\MedicalStudy\MedicalCenter
 * @license
 *
 * @property int	$msid			Medical Study Id
 * @property int	$mcid			Medical Center Id
 * @property int 	$patientid		Patient Id (Unique in a Medical Center Only)
 * @property string $reference 		Patient Code
 * @property date 	$birth_date 	Patient Birth Date
 * @property date 	$selection_date Selection Date
 * @property date 	$inclusion_date Inclusion Date
 * @property string $bras 			Bras
 * @property string $status 		Patient Status
 * @property string $reason 		Removed From the Study Reason
 * @property string $comments 		Comments
 * 
 * @method array monitorings() Retrieve all patient monitorings
 */
class Patient extends \Fox\Object {

	/**
	 * Link to Medical Study
	 */
	const LINK_MEDICAL_STUDY = 'medicalStudy';

	/**
	 * Link to Medical Center
	 */
	const LINK_MEDICAL_CENTER = 'medicalCenter';

	/**
	 * Link to Documents
	 */
	const LINK_DOCUMENTS = 'documents';

	/**
	 * Link to monitoring
	 */
	const LINK_MONITORINGS = 'monitorings';

	/**
	 * Link to monitoring
	 */
	const LINK_VISITS = 'visits';
			
	/**
	 * Unique id to handle correctly the MS breadcrumb
	 * @var string
	 */
	const BREADCRUMB_NODE = 'patients';
	
	/**
	 * Default status in included
	 */
	const STATUS_INCLUDED = 1;
	
	/**
	 * Patient Label 
	 * @return string
	 */
	public function label() {
		return $this->reference;
	}

}
\Fox\Dao::infos(Patient::className(),
new \Fox\Object\Info('ms_mc_patients', \Fox\Databases::DB_APP)
)->addAutoIncrementField('patientid');

// Link to Patient Attached Documents
\Fox\Object\Links::add(\Fox\Dao::link(Patient\Document::className(), Patient\Document::LINK_PATIENT)
->to(Patient::className(), Patient::LINK_DOCUMENTS)
->on('msid','mcid','patientid')
->versionFrom());

// Link to Patient monitoring
\Fox\Object\Links::add(\Fox\Dao::link(Patient\Monitoring::className(), Patient\Monitoring::LINK_PATIENT)
->to(Patient::className(), Patient::LINK_MONITORINGS)
->on('msid','mcid','patientid')
->orderBy('monitoring_date')
->orderBy('monitoringid')
->versionFrom());

// Link to Patient visits
\Fox\Object\Links::add(\Fox\Dao::link(Patient\Visit::className(), Patient\Visit::LINK_PATIENT)
->to(Patient::className(), Patient::LINK_VISITS)
->on('msid','mcid','patientid')
->versionFrom());